package com.wc.alorithm_luogu.P5731;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/4/22 11:19
 * @description https://www.luogu.com.cn/problem/P5731
 * 蛇形方阵
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[][] map = new int[n][n];

        // 偶数多加一圈
        int round = (n + 1) / 2;

        // 记录当前数字
        int num = 1;
        for (int i = 0; i < round; i++) {
            // 上 要画到底 1 2 3 4
            for (int j = i; j <= n - i - 1; j++) {
                map[i][j] = num++;
            }
            // 右 5 6 7
            for (int j = i + 1; j < n - i - 1; j++) {
                map[j][n - 1 - i] = num++;
            }
            // 下 7 8 9
            for (int j = n - i - 1; j > i; j--) {
                map[n - i - 1][j] = num++;
            }
            // 左 10 11 12
            for (int j = n - i - 1; j > i; j--) {
                map[j][i] = num++;
            }
        }
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                System.out.printf("%3d",map[j][k]);
            }
            System.out.println();
        }
    }
}
